package com.project.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.project.bean.FolloweBean;
import com.project.bean.PageBean;
import com.project.service.IFollowService;

@Controller
public class FollowController {
	@Autowired
	private IFollowService followservice;
	/**
	 * 添加关注
	 * @param id1 自己的ID（即发起关注者的ID）
	 * @param id2 对方的ID（即被关注者的ID）
	 * @return
	 */
	@RequestMapping(value="/follow/{id1}/{id2}",method=RequestMethod.POST)
	@ResponseBody
	public String addFollow(@PathVariable("id1")int id1,@PathVariable("id2")int id2) {
		String result="关注失败！";
		int i = followservice.addFollow(id1, id2);
		if(i==1) {
			result = "添加成功！";
		}
		return result;
	}
	/**
	 * 取消关注
	 * @param fid 数据库中关注表的id
	 * @param id1  自己的ID（即发起关注者的ID）
	 * @param id2 对方的ID（即被关注者的ID）
	 * @return
	 */
	@RequestMapping(value="/follow/{fid}/{id1}/{id2}",method=RequestMethod.DELETE)
	@ResponseBody
	public String delFollow(@PathVariable("fid")int fid,@PathVariable("id1")int id1,@PathVariable("id2")int id2) {
		String result = "取消关注失败！";
		int i = followservice.delFollow(fid, id1, id2);
		if(i==1) {
			result = "取消关注成功！";
		}
		return result;
	}
	/**
	 * 分页查询关注列表
	 * =====》注意中间区分字段 follows
	 * @param id
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/follow/follows/{id}/{page}/{size}",method=RequestMethod.GET)
	@ResponseBody
	public PageBean findFollows(@PathVariable("id")int id,@PathVariable("page")int page,@PathVariable("size")int size){
		PageBean bean = followservice.findFollowsByPage(id, page, size);
		return bean;
	}
	/**
	 * 分页查询粉丝列表
	 * =====》注意中间区分字段 fans
	 * @param id
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/follow/fans/{id}/{page}/{size}",method=RequestMethod.GET)
	@ResponseBody
	public PageBean findFans(@PathVariable("id")int id,@PathVariable("page")int page,@PathVariable("size")int size){
		PageBean bean = followservice.findFansByPage(id, page, size);
		return bean;
	}
	/**
	 * 分页查询好友列表
	 * =====》注意中间区分字段 friends
	 * @param id
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/follow/friends/{id}/{page}/{size}",method=RequestMethod.GET)
	@ResponseBody
	public PageBean findFriends(@PathVariable("id")int id,@PathVariable("page")int page,@PathVariable("size")int size){
		PageBean bean = followservice.findFriendsByPage(id, page, size);
		return bean;
	}
	@RequestMapping("/follow/fans")
	@ResponseBody
	public List<FolloweBean> findFansById(){
		int id=1;
		List<FolloweBean> list=followservice.findFansById(id);
		return list;		
	}
	@RequestMapping("/follow/follows")
	@ResponseBody
	public List<FolloweBean> findFollowsById(int id){
		List<FolloweBean> list=followservice.findFollowsById(id);
		return list;	
	}

}
